<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        @include('common.meta')
        <meta name="csrf-token" content="{{ csrf_token() }}">
        @include('common.script')
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>角色昵称</label>
                        <div class="layui-input-inline">
                            <input type="hidden" name="role_id" value="{{ $role->id }}"  />
                            <input type="text" id="L_username" name="role_name" required="" value="{{ $role->role_name }}" lay-verify="nikename" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
                    </div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
                function() {
                    $ = layui.jquery;
                    var form = layui.form,
                        layer = layui.layer;

                    //自定义验证规则
                    form.verify({
                        role_name: function(value) {
                            if (value.length < 2) {
                                return '角色名至少得2个字符啊';
                            }
                        },
                    });

                    //监听提交
                    form.on('submit(edit)',
                        function(data) {
                            //发异步，把数据提交给php
                            $.ajax({
                                url:'/admin/role/'+data.field.role_id,
                                type:'PUT',
                                dataType:'json',
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                },
                                data:data.field,
                                success:function (res){
                                    // 判断
                                    if(res.code == 1){
                                        layer.msg(res.message,{icon:1},function (){
                                            parent.location.reload(true)
                                        })
                                    }else {
                                        layer.msg(res.message,{icon:5})
                                    }
                                },
                                error:function (res){
                                }
                            });
                            return false;
                        });

                });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>